<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src='../static/js/jquery-3.6.0.min.js'></script>
    <script type="text/javascript">

        $(function () {
            // 页面加载完成后 代码自动执行
            bindbtn();
        })



        $(function(){
            bindbtn
        })

        $(function () {
            bindbtn2()
        })

        function bindbtn() {
            $('#btn111').click(function () { //绑定  找到id 为 btn111
                $.ajax({
                    url: '/ajax/test',
                    type: 'post',
                    // dataType:'JSON',
                    data: {a: 123, b: 'two'},
                    success: function (res) {
                        console.log(res)
                        console.log(res.name)
                    }
                })
            })
        }

        function bindbtn2() {
            $('#btn222').click(function () {
                $.ajax({
                    url: '/ajax/test',
                    type: 'post',
                    data: {
                        id: $('#id').val(),
                        psw: $('#psw').val()
                    },
                    dataType:'JSON',
                    success:function (res){
                        console.log('你好啊！！！'),
                        alert(res.id)
                    }

                })
            })

        }

    </script>

</head>

<body>
<h3>demo 1</h3>
<input id='btn111' type="button" class="button" value="点击我">
<!--    <button class="button" type="button">登录</button>-->
<h3>demo2</h3>
<input type="text" id="id" placeholder="用户id">
<input type="password" id="psw" placeholder="用户密码">
<input type="button" id="btn222" value="提交">

</body>
</html>